package cn.slipi.common.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * PluginDetailEnum
 */
@RequiredArgsConstructor
@Getter
public enum PluginDetailEnum {


    REQUEST(1, 0, "pre", "request"),

    FIREWALL(2, 0, "pre", "firewall"),

    SIGN(3, 0, "pre", "sign"),

    RATE_LIMITER(4, 0, "pre", "rate_limiter"),

    GRAY_RELEASE(5, 0, "pre", "gray_release"),

    HTTP(8, 0, "routing", "http"),

    RESPONSE(9, 0, "post", "response");


    private final int code;

    private final int role;

    private final String phase;

    private final String name;

    public PluginDetailEnum getPluginByName(String name) {
        return Arrays.stream(PluginDetailEnum.values())
                .filter(p -> StringUtils.equals(p.getName(), name))
                .findFirst()
                .orElse(PluginDetailEnum.HTTP);
    }


}
